﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Register.IDAL;
using System.Data.SqlClient;
using System.Data;
using Register.DBUtility;

namespace Register.DAL
{
    /// <summary>
    /// FileName: DictionaryDAL.cs
    /// CLRVersion: 4.0.30319.269
    /// Author: WangYan
    /// Corporation: 
    /// Description: 
    /// DateTime: 2012/6/23 16:12:56
    /// </summary>
   public class DictionaryDAL:IDictionaryDAL
    {
       /// <summary>
       /// 根据字典类型获取下一个记录的ID
       /// </summary>
       /// <param name="type">字典类型</param>
       /// <returns></returns>
       public string GetDataIDByType(string type)
       {
               String sql = "select Dictionary_ID from System_dictionary where Dictionary_Type=@type and Dictionary_State='1' ";
               SqlParameter[] paramters = new SqlParameter[] { new SqlParameter("@type", SqlDbType.VarChar) };
               paramters[0].Value = type;
               return (String)DbHelperSQL.Query(sql, paramters).Tables[0].Rows[0]["Dictionary_ID"];
       }

       /// <summary>
       /// 根据字典类型更新记录的ID
       /// </summary>
       /// <param name="type">字典类型</param>
       /// <param name="ID">当前编号</param>
       /// <returns></returns>
        public bool UpdateDataIDByType(string type, string ID)
        {
            String sql = "update System_dictionary set Dictionary_ID=@ID where Dictionary_Type=@type and Dictionary_State='1'";
            SqlParameter[] paramters = new SqlParameter[] { 
            new SqlParameter("@ID",SqlDbType.VarChar),
            new SqlParameter("@type",SqlDbType.VarChar)
            };
            paramters[0].Value = ID;
            paramters[1].Value = type;
            if (DbHelperSQL.ExecuteSql(sql, paramters) > 0)
                return true;
            else
                return false;
        }
    }
}
